package dy.com.udp.广播;

public class MessageCreator {
    private static final String SN_HEADER="收到暗号，我是（SN）：";
    private static final String PORT_HEADER="这是暗号，请回电端口（port）：";

    public static String buildWithPort(int port){
        return PORT_HEADER+port;
    }
    public static int parsePort(String s){
        if(s.startsWith(PORT_HEADER)){
            return Integer.parseInt(s.substring(PORT_HEADER.length()));
        }
        return -1;
    }

    public static String buildWithSn(String sn){
        return SN_HEADER+sn;
    }
    public static String parseSn(String s){
        if(s.startsWith(SN_HEADER)){
            return s.substring(SN_HEADER.length());
        }else{
            return null;
        }
    }
}
